<template>
	<view>
		<view class="uni-list">
			<view class="uni-list-cell uni-list-cell-pd"  v-for="(item,index) in gateways" :key="index" v-if="item.isVoice!=1">
				<view class="uni-list-cell-db" style="letter-spacing: 2rpx;font-weight: 500;color: #62b074;">{{item.deviceName}}</view>
				<view style="display: flex;">
					<view class="update" @click="operate(item.id,0)">
						<text>开启</text>
					</view>
					<view class="delete" @click="operate(item.id,1)">
						<text>关闭</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import Api from '@/common/api';
	export default {
		data() {
			return {
				gateways:[]
			}
		},
		onLoad(options) {
			let that = this;
			console.log("=======" + options.deviceId);
			console.log("====" + options.storeId);
			that.getGateways(options.deviceId,options.storeId);
		},
		methods: {
			async operate(gatewayDeviceId,type){
				let res = await Api.apiCall('GET', Api.gateway.operate, {gatewayDeviceId:gatewayDeviceId,type:type});
				if(res){
					if(res==1){
						uni.showToast({
							icon:'error',
							title:'请先开启包间'
						})
						return;
					}else{
						uni.showToast({
							icon:'success',
							title:'操作成功'
						})
					}
				}
			},
			async getGateways(deviceId,storeId){
				let res = await Api.apiCall('GET', Api.gateway.getGateways, {deviceId:deviceId,storeId:storeId});
				if(res){
					this.gateways = res;
					console.log(this.gateways)
				}
			}
		}
	}
</script>

<style>
	.update{
		width: 120rpx;
		height: 60rpx;
		background: #55bd70;
		border-radius: 10rpx;
		font-size: 24rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 60rpx;
		text-align: center;
		margin-top: 20rpx;
		margin-right: 20rpx;
		letter-spacing: 5rpx;
	}
	.delete{
		width: 120rpx;
		height: 60rpx;
		background: #747474;
		border-radius: 10rpx;
		font-size: 24rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 60rpx;
		text-align: center;
		margin-top: 20rpx;
		letter-spacing: 5rpx;
	}
	.button{
		margin-left: 30rpx;
		background-color: #44a17f;
		width: 100rpx;
		border-radius: 15rpx;
		text-align: center;
		letter-spacing: 2rpx;
		color: #ffffff;
	}
</style>
